package in.muton.edushare.components.tasks.invitations.api;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.url.EduShareURLPanel;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.model.IModel;

import com.edushare.common.dao.UserDeptLinkDAO;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.UserDeptLink;

public class DeptInvitation extends Invitation {
	private static final long serialVersionUID = -2434800039537107239L;

	public DeptInvitation(IModel<UserDeptLink> link) {
		this.deptLink = link;
	}

	@Override
	public void accept() {
		deptLink.getObject().setStatus(UserDeptLink.STATUS_ACTIVE);
		EduShareSession.get().getSessionORMInterface().commitAllChanges();
		postInvitationTasks();
	}

	@Override
	public void decline() {
		new UserDeptLinkDAO(EduShareSession.get().getSessionORMInterface())
				.remove(deptLink.getObject().getDepartmentLink(), deptLink
						.getObject().getUserLink());
	}

	@Override
	public EduShareURLPanel getDestURL() {
		return new EduShareURLPanel("link", new CayenneModel<Departments>(
				deptLink.getObject().getDepartmentLink()));
	}

	private IModel<UserDeptLink> deptLink;

	@Override
	public void postInvitationTasks() {
		// 1.Add user to open polls.
	}
}
